export class ServerError {
  static Failed = 'failed'
  static FormRequestError = 'Form request param error'
  static JwtExpire = 'expired jwt token'
  static PasswordError = 'crypto/bcrypt: hashedPassword is not the hash of the given password'
  static CaptchaError ='WRONG_RESPONSE'
  static CaptchaExpired ='RESPONSE_USED'

  static UserNotMatch = 'user not match'
  static UserNotFound = 'user not found'
  static UserChangePassFailed = 'user change password failed'

  static UserRegisterFailed = 'user register failed'
  static UserNameExist = 'user_name has existed'
  static EmailExist = 'email has existed'
  static PhoneExist = 'phone has existed'

  static AccountNotFound = 'account not found'
  static AccountBanned = 'account was banned'
  static AccountNameRequired = 'account name required'

  static TokenNotFound = 'token not found'
  static TokenCreateFailed = 'token create failed'
  static TokenUpdateFailed = 'token update failed'

  static Translate (code) {
    switch (code) {
      case ServerError.Failed:
        return '操作失败，未知错误'
      case ServerError.FormRequestError:
        return '表单提交错误'
      case ServerError.JwtExpire:
        return '登录已过期'
      case ServerError.PasswordError:
        return '密码错误'
      case ServerError.CaptchaError:
        return '验证码错误'
      case ServerError.CaptchaExpired:
        return '验证码过期'
      case ServerError.UserNotMatch:
        return '账户未匹配'
      case ServerError.UserNotFound:
        return '账户未找到'
      case ServerError.UserChangePassFailed:
        return '修改密码失败'
      case ServerError.UserRegisterFailed :
        return '账号注册失败'
      case ServerError.UserNameExist:
        return '该用户名已存在'
      case ServerError.EmailExist:
        return '该邮箱已存在'
      case ServerError.PhoneExist:
        return '该手机号已存在'
      case ServerError.AccountNotFound:
        return '账户未找到'
      case ServerError.AccountBanned:
        return '账户被封禁'
      case ServerError.AccountNameRequired:
        return '请填写账户名称'
      case ServerError.TokenNotFound:
        return '令牌未找到'
      case ServerError.TokenCreateFailed:
        return '令牌创建失败，请联系管理员'
      default:
        return code
    }
  }
}
